// ForceAssign.cpp: implementation of the ForceAssign class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ForceAssign.h"
#include "ForceAssignStrategy.h"
#include "GeneralForceAssignStrategy.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC_CREATE(ForceAssign, FunctionObject, FunctionObject::eFORCEASSIGN)

ForceAssign::ForceAssign()
{
	m_nStrategyNum = eGENERALSTRATEGY;
	m_pStrategy = NULL;
}

ForceAssign::~ForceAssign()
{
	ClearStrategy();
}

BOOL ForceAssign::Execute()
{
	if(m_pStrategy == NULL || m_pStrategy->StrategyNum() != m_nStrategyNum)
	{
		ClearStrategy();
		m_pStrategy = new GeneralForceAssignStrategy;
		m_pStrategy->SetOwner(this);
	}
	return m_pStrategy->Execute();
}

void ForceAssign::ClearStrategy()
{
	if(m_pStrategy != NULL)
	{
		delete m_pStrategy;
		m_pStrategy = NULL;
	}
}